package dynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName InvocationProxy
 * @Description TODO
 * @Author 李奉武
 * @Motto 逆水行舟, 不进则退
 * @Date 2022/3/31 9:26
 * @Version 1.0
 */
public class InvocationProxy implements InvocationHandler{

    private Rent rent;

    //构造业务接口
    public void setRent(Rent rent) {
        this.rent = rent;
    }

    //生成代理对象
    public Rent getProxy(){
        return (Rent) Proxy.newProxyInstance(InvocationProxy.class.getClassLoader(), rent.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        sum();
        Object invoke = method.invoke(rent, args);
        longs();
        return invoke;
    }

    public void sum(){
        System.out.println("计算总价");
    }

    public void longs(){
        System.out.println("计算租期");
    }
}
